﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.MountAndBlade.View.Scripts.HandPose
// Assembly: TaleWorlds.MountAndBlade.View, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 61152EB8-513B-4D4A-8AC0-0D1465C6CF6C
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\Modules\Native\bin\Win64_Shipping_Client\TaleWorlds.MountAndBlade.View.dll

using TaleWorlds.Core;
using TaleWorlds.Engine;
using TaleWorlds.Library;

#nullable disable
namespace TaleWorlds.MountAndBlade.View.Scripts
{
  public class HandPose : ScriptComponentBehavior
  {
    private MBGameManager _editorGameManager;
    private bool _initiliazed;
    private bool _isFinished;

    protected override void OnEditorInit()
    {
      base.OnEditorInit();
      if (Game.Current != null)
        return;
      this._editorGameManager = (MBGameManager) new EditorGameManager();
    }

    protected override void OnEditorTick(float dt)
    {
      if (!this._isFinished && this._editorGameManager != null)
        this._isFinished = !this._editorGameManager.DoLoadingForGameManager();
      if (Game.Current != null && !this._initiliazed)
      {
        AnimationSystemData animationSystemData = Game.Current.DefaultMonster.FillAnimationSystemData(MBActionSet.GetActionSet(Game.Current.DefaultMonster.ActionSetCode), 1f, false);
        this.GameEntity.CreateSkeletonWithActionSet(ref animationSystemData);
        this.GameEntity.CopyComponentsToSkeleton();
        this.GameEntity.Skeleton.SetAgentActionChannel(0, ActionIndexCache.Create("act_tableau_hand_armor_pose"));
        this.GameEntity.Skeleton.TickAnimationsAndForceUpdate(0.01f, this.GameEntity.GetGlobalFrame(), true);
        this.GameEntity.Skeleton.Freeze(false);
        this.GameEntity.Skeleton.TickAnimationsAndForceUpdate(1f / 1000f, this.GameEntity.GetGlobalFrame(), false);
        this.GameEntity.Skeleton.SetAnimationParameterAtChannel(0, MBMath.ClampFloat(0.0f, 0.0f, 1f));
        this.GameEntity.Skeleton.SetUptoDate(false);
        this.GameEntity.Skeleton.Freeze(true);
        this._initiliazed = true;
      }
      if (!this._initiliazed)
        return;
      this.GameEntity.Skeleton.Freeze(false);
      this.GameEntity.Skeleton.TickAnimationsAndForceUpdate(1f / 1000f, this.GameEntity.GetGlobalFrame(), false);
      this.GameEntity.Skeleton.SetAnimationParameterAtChannel(0, MBMath.ClampFloat(0.0f, 0.0f, 1f));
      this.GameEntity.Skeleton.SetUptoDate(false);
      this.GameEntity.Skeleton.Freeze(true);
    }
  }
}
